package jdbc;

import java.sql.Connection;
import java.sql.Statement;
import java.util.Scanner;

public class PWDDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要修改用户名：");
        String username = sc.nextLine();
        System.out.println("请输入修改后的密码：");
        String password = sc.nextLine();
        System.out.println("请输入修改后的昵称：");
        String nickname = sc.nextLine();
        System.out.println("请输入修改后的年龄：");
        int age = Integer.parseInt(sc.nextLine());
        try(Connection connection = DEUtil.getConnection()) {
            String sql = "UPDATE user SET password='"+password+"',nickname='"+nickname+"',age="+age+" WHERE username='"+username+"'";
            Statement statement = connection.createStatement();
            int num = statement.executeUpdate(sql);
            System.out.println(num>0?"修改成功":"修改失败");
        }
        catch (Exception e) {
            e.printStackTrace();

        }
    }
}
